home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Demos / Tools / AppMaker / Examples / pre-built AMReminder / Procedural / MainWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-04  |  5.6 KB  |  253 lines  |  [TEXT/MMCC]

  1. /* MainWindow.c */
  2. /* Created 01/01/95 12:01 PM by AppMaker */
  3.  
  4. #include <Types.h>
  5. #include <Quickdraw.h>
  6. #include <Controls.h>
  7. #include <Dialogs.h>
  8. #include <Events.h>
  9. #include <Lists.h>
  10. #include <Menus.h>
  11. #include <Resources.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include "ResourceDefs.h"
  15. #include "Globals.h"
  16. #include "Miscellany.h"
  17. #include "Scrolling.h"
  18. #include "WindowAids.h"
  19. #include "AMReminderData.h"
  20. #include "Add.h"
  21. #include "MainWindow.h"
  22.  
  23. #define LogoPicture        1
  24. #define YearLabel        2
  25. #define RemindersLabelLabel        3
  26. #define RemindersList        4
  27. #define AddButton        5
  28. #define EditButton        6
  29. #define DeleteButton        7
  30.  
  31. static void BuildRemindersList    (void);
  32. static void DoAddButton (void);
  33. static void DoEditButton (void);
  34. static void DoDeleteButton (void);
  35.  
  36. /*----------*/
  37. static void BuildRemindersList    ()
  38. {
  39.     Rect            bounds;
  40.  
  41.     SetWFont (RemindersList);
  42.     GetWRect (RemindersList, &bounds);
  43.     cur->RemindersHandle = NewV1List (bounds, qd.thePort);
  44.     AddToList ("\pOne",   cur->RemindersHandle);
  45.     AddToList ("\pTwo",   cur->RemindersHandle);
  46.     AddToList ("\pThree", cur->RemindersHandle);
  47.     AddToList ("\pInfinity",  cur->RemindersHandle);
  48.     LDoDraw (true, cur->RemindersHandle);
  49.  
  50. } /*BuildRemindersList*/
  51.  
  52. /*----------*/
  53. static void DoAddButton ()
  54. {
  55.     AddRec                AddInfo;
  56.     register AddRecPtr    info;
  57.  
  58.     info = &AddInfo;
  59.     /*initialize Add info*/
  60.     info->LogoData = nil;
  61.     info->DateText [0] = 0;
  62.     info->TimeText [0] = 0;
  63.     info->AmPmChoice = 1;
  64.     info->MessageText [0] = 0;
  65.     info->DisplayIconChecked = false;
  66.     info->DisplayAlertChecked = false;
  67.     info->PlaySoundChecked = false;
  68.     info->SoundChoice = 1;
  69.  
  70.     if (GetAdd (&AddInfo)) {
  71.         /*use Add info*/
  72.     }
  73. } /*DoAddButton*/
  74.  
  75. /*----------*/
  76. static void DoEditButton ()
  77. {
  78.     AddRec                AddInfo;
  79.     register AddRecPtr    info;
  80.  
  81.     info = &AddInfo;
  82.     /*initialize Add info*/
  83.     info->LogoData = nil;
  84.     info->DateText [0] = 0;
  85.     info->TimeText [0] = 0;
  86.     info->AmPmChoice = 1;
  87.     info->MessageText [0] = 0;
  88.     info->DisplayIconChecked = false;
  89.     info->DisplayAlertChecked = false;
  90.     info->PlaySoundChecked = false;
  91.     info->SoundChoice = 1;
  92.  
  93.     if (GetAdd (&AddInfo)) {
  94.         /*use Add info*/
  95.     }
  96. } /*DoEditButton*/
  97.  
  98. /*----------*/
  99. static void DoDeleteButton ()
  100. {
  101. } /*DoDeleteButton*/
  102.  
  103. /*----------*/
  104. void OpenMainWindow    (Str255        fName,
  105.                          short        vRefNum,
  106.                          short        fRefNum)
  107. {
  108.     WindowPtr        newWindow;
  109.     Rect            bounds;
  110.  
  111.     newWindow = GetWindow (WIND_MainWindow);
  112.     if (fName [0] != 0) {
  113.         SetWTitle (newWindow, fName);
  114.     }
  115.     SetPort (newWindow);
  116.     SetNewInfo (newWindow);
  117.     cur->vScroll = nil;
  118.     cur->hScroll = nil;
  119.     cur->fileNum    = fRefNum;
  120.     cur->volNum        = vRefNum;
  121.     cur->dirty        = false;
  122.     cur->filename    = NewString (fName);
  123.     cur->windowKind = WMainWindow;
  124.     ((WindowPeek) curWindow)->windowKind = userKind + WMainWindow;
  125.     cur->witlHandle = GetResource ('Witl', WIND_MainWindow);
  126.     cur->wictHandle = GetResource ('Wict', WIND_MainWindow);
  127.  
  128.     BuildRemindersList ();
  129.     cur->AddHandle = GetNewControl (CNTL_Add, newWindow);
  130.     cur->EditHandle = GetNewControl (CNTL_Edit, newWindow);
  131.     cur->DeleteHandle = GetNewControl (CNTL_Delete, newWindow);
  132.     cur->text = nil;
  133.  
  134.     ShowWindow (newWindow);
  135.  
  136. } /*OpenMainWindow*/
  137.  
  138. /*----------*/
  139. void CloseMainWindow    (void)
  140. {
  141.     LDispose (cur->RemindersHandle);
  142.  
  143.     DisposHandle ((Handle) cur->filename);
  144.     DiscardInfo (curWindow);
  145. } /*CloseMainWindow*/
  146.  
  147. /*----------*/
  148. void ControlMainWindow  (ControlHandle        whichControl,
  149.                          short                whichPart,
  150.                          Point                where)
  151. {
  152.     Rect            bounds;
  153.  
  154.     if ((whichControl == (**(cur->RemindersHandle)).vScroll)
  155.     ||  (whichControl == (**(cur->RemindersHandle)).hScroll)) {
  156.         if (LClick (where, 0, cur->RemindersHandle)) {
  157.             /*double click in scroll bar*/
  158.         }
  159.     }
  160.     if (whichControl == cur->AddHandle) {
  161.         if (TrackButton (cur->AddHandle, where)) {
  162.             DoAddButton ();
  163.         }
  164.     }
  165.     if (whichControl == cur->EditHandle) {
  166.         if (TrackButton (cur->EditHandle, where)) {
  167.             DoEditButton ();
  168.         }
  169.     }
  170.     if (whichControl == cur->DeleteHandle) {
  171.         if (TrackButton (cur->DeleteHandle, where)) {
  172.             DoDeleteButton ();
  173.         }
  174.     }
  175.  
  176. } /*ControlMainWindow*/
  177.  
  178. /*----------*/
  179. void MouseInMainWindow    (Point        where,
  180.                          short        modifiers)
  181. {
  182.     Rect            bounds;
  183.  
  184.     if (PtInRect (where, &(**(cur->RemindersHandle)).rView)) {
  185.         if (LClick (where, modifiers, cur->RemindersHandle)) {
  186.             /*double click*/
  187.         }
  188.         if (GetListChoice (&cur->RemindersChoice, cur->RemindersHandle)) {
  189.             /* something is selected */
  190.         }
  191.     }
  192.  
  193. } /*MouseInMainWindow*/
  194.  
  195. /*----------*/
  196. void TypeInMainWindow   (char        ch)
  197. {
  198.     if (cur->text == nil) {
  199.         SysBeep (1);
  200.     } else {
  201.         TEKey (ch, cur->text);
  202.         cur->dirty = true;
  203.     }
  204. } /*TypeInMainWindow*/
  205.  
  206. /*----------*/
  207. void UpdateMainWindow (void)
  208. {
  209.     Rect            bounds;
  210.  
  211.     GetWRect (LogoPicture, &bounds);
  212.     DrawPictureID (PICT_Logo, bounds);
  213.     SetWFont (YearLabel);
  214.     GetWRect (YearLabel, &bounds);
  215.     TextIDBox (TEXT_Year, bounds);
  216.     SetWFont (RemindersLabelLabel);
  217.     GetWRect (RemindersLabelLabel, &bounds);
  218.     TextIDBox (TEXT_RemindersLabel, bounds);
  219.     SetWFont (RemindersList);
  220.     LUpdate (qd.thePort->visRgn, cur->RemindersHandle);
  221.     bounds = (**(cur->RemindersHandle)).rView;
  222.     InsetRect (&bounds, -1, -1);
  223.     FrameRect (&bounds);
  224.     SetWFont (AddButton);
  225.     Draw1Control (cur->AddHandle);
  226.     SetWFont (EditButton);
  227.     Draw1Control (cur->EditHandle);
  228.     SetWFont (DeleteButton);
  229.     Draw1Control (cur->DeleteHandle);
  230. } /*UpdateMainWindow*/
  231.  
  232. /*----------*/
  233. void ActivateMainWindow    (Boolean    activate)
  234. {
  235.     LActivate (activate, cur->RemindersHandle);
  236.  
  237. } /*ActivateMainWindow*/
  238.  
  239. /*----------*/
  240. void ResizeMainWindow    (void)
  241. {
  242.     /* application-specific code to resize items in window */
  243. } /*ResizeMainWindow*/
  244.  
  245. /*----------*/
  246. pascal void ScrollMainWindow    (short        newValue,
  247.                                  short        oldValue)
  248. {
  249.     /* application-specific code to scroll window */
  250. } /*ScrollMainWindow*/
  251.  
  252. /* MainWindow */
  253.